﻿
//
// Copyright (c) 2024 BPer
//
#ifndef SRC_BPERWEBRTC_BPERUDPHANDLEH_H_
#define SRC_BPERWEBRTC_BPERUDPHANDLEH_H_

#include <bperutil/sys/BPerThread.h>
#include <bperutil/sys/BPerSocket.h>

typedef void* (*bPer_rtcsocket_thread_app)(void *obj);



typedef struct{
	bPer_socket_t fd;
	BPerBool isControlled;
	BPerBool isStart;
	BPerBool isLoop;
	BPerBool notRemoteInit;

	BPerIpFamilyType   familyType;
	BPerSocketProtocol socketProtocol;

	int32_t headerLen;

	bPer_thread_t threadId;
	bPer_thread_mutex_t sendLock;

	char* buffer;

	void* user;
	void (*receive)(char *data, int32_t nb_data,void* user);
	void (*startStunTimer)(void* user);

	BPerIpAddress local_addr;
	BPerIpAddress remote_addr;

}BPerRtcSocketSession;

typedef struct {
	BPerRtcSocketSession session;
	void (*updateRemoteAddress)(BPerRtcSocketSession *sock,char* remoteIp,int32_t port);
	void (*start)(BPerRtcSocketSession* sock);
	void (*stop)(BPerRtcSocketSession* sock);
	int32_t (*write)(BPerRtcSocketSession* sock,char* buffer,int32_t bufferLen);
}BPerRtcSocket;

int32_t bPer_create_rtcsocket(BPerRtcSocket* sock,BPerIpFamilyType familyType,BPerSocketProtocol protocol,int32_t plocalPort);

#if BPer_Enable_Tcp_Srs
int32_t bPer_create_rtcsocket_srs(BPerRtcSocket* sock,BPerSocketProtocol protocol);
#endif

void bPer_destroy_rtcsocket(BPerRtcSocket* sock);


#endif /* SRC_BPERWEBRTC_BPERUDPHANDLEH_H_ */
